package com.sgz.androidlib.others;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

import com.android.sgzcommon.activity.BaseActivity;
import com.android.sgzcommon.service.entity.VersionDownload;
import com.android.sgzcommon.sound.SoundManager;
import com.android.sgzcommon.utils.NotificationUtils;
import com.android.sgzcommon.utils.SystemUtils;
import com.android.sgzcommon.view.SuButton;
import com.android.sgzcommon.view.TitleBar;
import com.sgz.androidlib.R;
import com.sgz.androidlib.others.sample.NotificationResultActivity;
import com.sgz.androidlib.others.sample.NotificationStackResultActivity;
import com.sgz.androidlib.others.sample.TestBaseAdapterActivity;
import com.sgz.androidlib.others.sample.TestCreateCodeActivity;
import com.sgz.androidlib.others.sample.TestRecyclerViewDecorationActivity;
import com.sgz.androidlib.others.sample.TestScanCodeActivity;

import org.greenrobot.eventbus.EventBus;

import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author sgz
 * @date 2020/9/24
 */
public class TestOthersActivity extends BaseActivity {

    @BindView(R.id.tb_title)
    TitleBar mTbTitle;
    @BindView(R.id.btn_code)
    Button mBtnCode;
    @BindView(R.id.btn_version_update)
    Button mBtnOthers;
    @BindView(R.id.btn_base_adapter)
    Button mBtnBaseAdapter;
    @BindView(R.id.btn_vibrate)
    Button mBtnVibrate;
    @BindView(R.id.btn_recyclerview_decoration)
    SuButton mBtnRecyclerviewDecoration;
    @BindView(R.id.btn_notification)
    SuButton mBtnNotification;
    @BindView(R.id.btn_notification_activity)
    SuButton mBtnNotificationActivity;
    @BindView(R.id.btn_notification_stack_activity)
    SuButton mBtnNotificationStackActivity;
    @BindView(R.id.btn_notification_version)
    SuButton mBtnNotificationVersion;
    @BindView(R.id.btn_nbzxing)
    SuButton mBtnNbzxing;
    @BindView(R.id.btn_voice)
    SuButton mBtnVoice;

    private int mProgress;
    private int voiceId;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    mProgress++;
                    if (mProgress > 100) {
                        mProgress = 0;
                    }
                    NotificationUtils.versionNotification(mContext, "新版本下载", mProgress, R.mipmap.ic_launcher_round);
                    if (mProgress < 100) {
                        sendEmptyMessageDelayed(1, 1000);
                    }
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_others);
        ButterKnife.bind(this);
        voiceId = SoundManager.getInstance(mContext).load(R.raw.scan);
    }

    @OnClick({R.id.btn_base_adapter, R.id.btn_code, R.id.btn_version_update, R.id.btn_vibrate, R.id.btn_recyclerview_decoration, R.id.btn_notification, R.id.btn_notification_version, R.id.btn_notification_activity, R.id.btn_notification_stack_activity, R.id.btn_nbzxing, R.id.btn_voice})
    public void onViewClicked(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.btn_base_adapter:
                intent = new Intent(mContext, TestBaseAdapterActivity.class);
                break;
            case R.id.btn_code:
                intent = new Intent(mContext, TestCreateCodeActivity.class);
                break;
            case R.id.btn_recyclerview_decoration:
                intent = new Intent(mContext, TestRecyclerViewDecorationActivity.class);
                break;
            case R.id.btn_version_update:
                final String url = "http://139.9.86.110:80/upload/files/20200929/盛马桂v1_0_9_1601367084098.apk";
                EventBus.getDefault().post(new VersionDownload(url, 101));
                break;
            case R.id.btn_vibrate:
                SystemUtils.vibrate(mContext);
                break;
            case R.id.btn_notification:
                NotificationUtils.notificate(mContext, R.mipmap.ic_launcher_round, "通知", "这是测试通知的文本", false);
                break;
            case R.id.btn_notification_version:
                mHandler.sendEmptyMessageDelayed(1, 1000);
                break;
            case R.id.btn_notification_activity:
                NotificationUtils.notificateActivity(mContext, R.mipmap.ic_launcher_round, "通知", "这是测试通知的文本", false, NotificationResultActivity.class);
                break;
            case R.id.btn_notification_stack_activity:
                NotificationUtils.notificateStackActivity(mContext, R.mipmap.ic_launcher_round, "通知", "这是测试通知的文本，跳转Activity", false, NotificationStackResultActivity.class);
                break;
            case R.id.btn_nbzxing:
                intent = new Intent(mContext, TestScanCodeActivity.class);
                break;
            case R.id.btn_voice:
                SoundManager.getInstance(mContext).play(voiceId);
                break;
        }
        if (intent != null) {
            startActivity(intent);
        }
    }

    @Override
    protected void onDestroy() {
        SoundManager.getInstance(mContext).release();
        super.onDestroy();
    }
}
